public class Remove {
    public static void main(String[] args) {
        int[] nums = new int[]{3,2,2,3};
        int val = 3;
        int k = removeElement(nums,val);
    }
    public static int removeElement(int[] nums, int val) {
            int count = 0;
            //统计个数
            for(int i = 0;i < nums.length;i++) {
                if(nums[i] == val) {
                    count++;
                }
            }
            //移除元素
            for(int i = 0;i < nums.length;i++) {
                if(nums[i] == val) {
                    for(int j = i+1;j < nums.length; j++) {
                        if(nums[i] != nums[j]){
                            int tmp = 0;
                            tmp = nums[i];
                            nums[i] = nums[j];
                            nums[j] = tmp;
                            break;
                        }
                    }
                }
            }
            for (int j = 0; j < nums.length; j++) {
                System.out.print(nums[j]);
            }
            return nums.length - count;
    }
}
